/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.MemberDao;
import entity.Member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.DeleteCollection;

@WebServlet("/dcs")
public class DeleteCollectionServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int bookId=Integer.parseInt(req.getParameter("id"));
        String username=(String)req.getSession().getAttribute("username");
        Member member=new MemberDao().getMemberByName(username);
        Boolean bool=new DeleteCollection().deleteCollection(member.getId(),bookId);
        resp.setContentType("text/html;charset=utf-8");
        if(bool==false){
            resp.getWriter().println("<script language='javascript'>alert('取消收藏失败！');window.location.href='Collection.jsp?name="+username+"';</script>");
        }
        else{           
            resp.getWriter().println("<script language='javascript'>alert('取消收藏成功！');window.location.href='Collection.jsp?name="+username+"';</script>");
        }
        resp.getWriter().println("<a href='Collection.jsp?name="+username+"'>返回收藏夹</a>");
    }
    
}
